package PAT;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class PAT1030 {
    private static int minDistance = 1 << 30;
    private static int minCost = 1 << 30;
    private static List<Integer> ans = new ArrayList<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int s = scanner.nextInt();
        int e = scanner.nextInt();
        int[][] distances = new int[n][n];
        int[][] costs = new int[n][n];
        while (m-- > 0) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            distances[a][b] = scanner.nextInt();
            costs[a][b] = scanner.nextInt();
        }
        ArrayList<Integer> list = new ArrayList<>();
        list.add(s);
        dfs(s, e, distances, costs, new boolean[n], list , 0, 0);
        for (Integer an : ans) {
            System.out.print(an + " ");
        }
        System.out.print(minDistance+" "+minCost);
    }

    private static void dfs(int index, int e, int[][] distances, int[][] costs, boolean[] visited, List<Integer> list, int distance, int cost) {
        if(visited[index]) return;
        if (index == e) {
            if (distance < minDistance) {
                ans = new ArrayList<>(list);
                minDistance = distance;
                minCost = cost;
            } else if (distance == minDistance) {
                if (cost < minCost) {
                    minCost = cost;
                    ans = new ArrayList<>(list);
                }
            }
        }
        int[] children = distances[index];
        for (int i=0;i<children.length ; i++) {
            if(distances[index][i]!=0){
                list.add(i);
                dfs(i,e,distances,costs,visited,list,distance+distances[index][i],cost+costs[index][i]);
                list.remove(list.size()-1);
            }
        }

    }
}
